/**
 * Created by IntelliJ IDEA
 *
 * @author zhengjie
 * @Date:2022/1/7 16:29
 * @Version 1.0
 */
package com.zj.ssm.controller;

import com.zj.ssm.aop.Log;
import com.zj.ssm.pojo.domain.query.StaffQuery;
import com.zj.ssm.pojo.domain.vo.StaffVO;
import com.zj.ssm.result.AjaxResult;
import com.zj.ssm.service.StaffService;
import com.zj.ssm.util.OSSUtil;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("sta")
public class StaffController {

    @Autowired
    private StaffService staffService;

    @Autowired
    private OSSUtil ossUtil;

    @RequestMapping("query")
    public AjaxResult query(StaffQuery query){
        return staffService.queryStaff(query);
    }

    @RequestMapping("add")
    @Log("添加员工")
    public AjaxResult add(StaffVO staffVO, MultipartFile headImg)throws Exception{

        String path = ossUtil.uploadOSS(headImg);
        staffVO.setImgURL(path);

        return staffService.addStaff(staffVO);
    }

    @RequestMapping("getEmployee")
        public AjaxResult getSta(Integer id){
            return staffService.getSta(id);
    }

    @RequestMapping("update")
    @Log("修改员工")
    public AjaxResult updateSta(StaffVO staffVO, MultipartFile headImg){

        long size = headImg.getSize();

        if (size>0){
            String path = ossUtil.uploadOSS(headImg);
            staffVO.setImgURL(path);
        }

        return staffService.updateSta(staffVO);
    }

    @RequestMapping("updatePeo/{id}")
    @Log("员工离职")
    public AjaxResult updatePeo(@PathVariable("id")Integer id){
        return staffService.updatePeo(id);
    }

    @RequestMapping("peoUpdate/{id}")
    @Log("员工复职")
    public AjaxResult peoUpdate(@PathVariable("id")Integer id){
        return staffService.peoUpdate(id);
    }



}
